package com.avic.service.impl;

import com.avic.common.util.ex.BizErrorCode;
import com.avic.common.util.ex.BizException;
import com.avic.dal.condition.InformationReportListCondition;
import com.avic.dal.model.InformationReport;
import com.avic.service.InformationReportService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @Description
 * @Author huangsheng
 * @Date 2018/10/24 11:46
 */
@Service
@Data
@Slf4j
public class InformationReportServiceImpl extends AbstractServiceImpl implements InformationReportService {

    @Override
    public List<InformationReport> informationReportList(InformationReportListCondition informationReportListCondition) {
        return informationReportMapper.itemList(informationReportListCondition);
    }

    @Override
    public int informationReportListCount(InformationReportListCondition informationReportListCondition) {
        return informationReportMapper.queryRecordsTotal(informationReportListCondition);
    }

    @Override
    public int informationReportNumberCount(String reportNumber) {
        return informationReportMapper.queryItemCountByNumber(reportNumber);
    }

    @Override
    public String createInformationReport(InformationReport informationReport) {
        try {
            String resourceId = UUID.randomUUID().toString();
            informationReport.setId(resourceId);
            informationReportMapper.insert(informationReport);
            return resourceId;
        } catch (Exception e) {
            log.error("创建信息报告数据时发生错误 {}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR);
        }
    }

    @Override
    public InformationReport getInformationReportById(String id) {
        return informationReportMapper.queryItemById(id);
    }

    @Override
    public void updateInformationReport(InformationReport informationReport) {
        try {
            informationReportMapper.update(informationReport);
        } catch (Exception e) {
            log.error("更新信息报告数据时发生错误 {}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR);
        }
    }

    @Override
    public void deleteInformationReport(String id) {
        try {
            informationReportMapper.delete(id);
        } catch (Exception e) {
            log.error("删除信息报告数据时发生错误 {}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR);
        }
    }
}
